/*
 * Copyright 2009 Max Kugland
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
package org.splink.deepsplink.page.request {
	import flash.display.Sprite;

	/**
	 * The <code>InitializeShowHideFinalize</code> builds a request following the pattern:
	 * 
	 * 1) inject current page parametes into to pages which are to be opened (from bottom to top)
	 * 2) initialize the pages which are to be opened (from bottom to top)
	 * page and the page which is to be shown
	 * 3) show the pages which are to be opened (from bottom to top)
	 * 4) hide old pages, from top to the first common node of the currently shown 
	 * 5) finalize the hidden pages
	 * 
	 * @author Max Kugland
	 */
	final internal class InitializeShowHideFinalize implements IRequestBuilder {
		private var _builder : OperationBuilder;

		public function InitializeShowHideFinalize(overlayIds : Array) {
			_builder = new OperationBuilder(overlayIds);
		}
		
		/**
		 * @inheritDoc
		 */
		public function build(display : Sprite, doOpen : Array, all : Array, pageParams : Array) : Array {
			var ar : Array = new Array();
			
			_builder.addInitializeOperations(display, ar, doOpen, all, pageParams);
			_builder.addShowOperations(display, ar, doOpen, all);
			_builder.addHideOperations(ar, doOpen, all);
			_builder.addFinalizeOperations(ar, doOpen, all);
			
			return ar;
		}
		
		/**
		 * @inheritDoc
		 */
		public function get type() : String {
			return "init-show-hide-finalize";
		}
	}
}
